'''

1、获取数据

2、k-means聚类

3、聚类结果显示

'''
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris
from matplotlib import pyplot as plt
iris = load_iris()

# k-means聚类
kms = KMeans(n_clusters=3)
kms.fit(iris.data)

# 聚类结果显示
predict = kms.predict(iris.data)
print(predict)

# 画图展示
plt.figure(figsize=[4,4])

colors = ["red", 'green','blue']
# 选两个画散点图
plt.scatter(iris.data[:,0], iris.data[:,1],c=colors )

plt.xlabel("feature1")
plt.ylabel("feature2")
plt.show()

